a = int(input())
b1 = a % 10
b2 = a // 10 % 10
b3 = a // 100 % 10
b4 = a // 10000
if (999 < a < 10000) and b1 %  b1 == 0 and b2 % b2 == 0 and b3 % b3 == 0 and b4 % b3 == 0:
    print('')
else:
        print('0')
